package user

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/client/user"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserCodeCountLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员管理 - 会员管理 - 会员详情操作: 更新会员打码量
func NewUpdateUserCodeCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserCodeCountLogic {
	return &UpdateUserCodeCountLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserCodeCountLogic) UpdateUserCodeCount(req *types.UpdateUserCodeCountRequest) (resp *types.UpdateUserCodeCountResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.User.SetUserValidMark(l.ctx, &user.SetValidMarkRequest{
		UserId:    req.UserId,
		ValidMark: float64(req.CodeCount),
	})
	if err != nil {
		return nil, err
	}
	return &types.UpdateUserCodeCountResponse{}, nil
}
